
<form id="editoraddform" method="post" class="form-horizontal" role="form">
	[#list collections as collect]
		<div class="mian_collect">
			<input type="hidden" name="collectId" value="${collect.id!}">
			<div class="form-group">
				<label class="col-sm-3 control-label" id="clickforpro"><input class="collect_check" type="checkbox">第${collect.stage!}阶段(${collect.amount!}元)</label>
				<div class="col-sm-8"></div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label" id="clickforpro">收款金额</label>
				<div class="col-sm-8" style="padding-top: 7px;">
					${collect.amount!}元
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label" id="clickforpro">收款日期</label>
				<div class="col-sm-8">
					<input class="startdate" name="startdate" style="width:120px;">
				</div>
			</div>
			<div class="form-group" name="pzdiv">
				<label class="col-sm-2 control-label" id="clickforpro">收款凭证</label>
				<div class="col-sm-8">
					<button type="button" class="btn btn-default" onclick="uploadpz(this)">上传凭证</button>
				</div>
				<div class="col-sm-8" name="pzhref" style="margin-left: 16px;">
					
				</div>
			</div>
		</div>
	[/#list]
	<div class="form-group" style="margin-top: 10px;">
		<div class="col-sm-offset-2 col-sm-10">
			<input id="addoreditsub" type="button" onclick="subForm()"  class="btn btn-default" value="提交" />
		</div>
	</div>
	<input type="hidden" name="pid" id="pid">
</form>
<script type="text/javascript">

var clicknode;
function uploadpz(node){
	//alert($(node).parents(".pzdiv").find(".pzhref").append("sssssss"));
	//var param ={id:newproid};
	clicknode=node;
	exceldialog = art.dialog.uploadFile("上传凭证",{callback:"uploadcallback",userpath:"admin",extensions:"gif,jpg,png,jepg"});
}

function uploadcallback(response){
	
	//alert($(clicknode).text());
	//alert(params.id);
	exceldialog.close();
	$(clicknode).parents("[name='pzdiv']").find("[name='pzhref']").children().remove();
	$(clicknode).parents("[name='pzdiv']").find("[name='pzhref']").append("<a target='_blank' class='pzhengs'  href='"+response.url+"'>"+response.url+"</a>");
}

function subForm(){
	var cemMember={};
	var collections=[];
	var len=$(".collect_check:checked").length;
	if(len==0){
		alert("请先勾选");
		return false;
	}
	var issub=true;
	$(".collect_check").each(function(){
		if($(this).is(":checked")){
			var fath=$(this).parents(".mian_collect");
			var id=fath.find("[name='collectId']").val();
			var state=1;
			var proveImg=fath.find(".pzhengs").text();
			var collecttime=fath.find("[name='startdate']").val();
			if(collecttime==""){
				alert("收款时间不能为空");
				issub=false;
				return false;
			}
			collections.push({
				id:id,
				state:state,
				proveImg:proveImg,
				collecttime:collecttime
			});
		}
	})
	cemMember.collections=collections;
	//alert(JSON.stringify(cemMember));
	if(issub){
		art.dialog.post({
			  
			type : "post",
			dataType : "json",
			url : "/member/shoukuan.do",
			contentType : "application/json; charset=utf-8",
	        data:JSON.stringify(cemMember),
			success : function(data) {
				 if(data.success){
					 alert(data.msg);
					 location.reload();
				 }else{
					 alert(data.msg);
				 }
			}
	 
			},"数据正在提交.... ");
	}
}

$(document).ready(function(){
	 $(".startdate").datebox({
	        formatter: function (date) {
	            var y = date.getFullYear();
	            var m = date.getMonth() + 1;
	            var d = date.getDate();
	            return y + '-' + m + '-' + d;
	        },
	        onSelect: function (dateselect) {
	            //enddate清空
	            $('#enddate').datebox('setValue', '');
	            $("#enddate").datebox("calendar").calendar({
	                validator: function (date) {
	                    return dateselect <= date;
	                }
	            });
	        }
	    });
})
</script>